/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prabhu.jeazyprops.encryption;

import com.prabhu.jeazyprops.interfaces.PropsEncrypt;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * Base64 Encryption
 * @author Pinky
 */
public class Base64
        implements PropsEncrypt
{

    /**
     * Decrypts the String
     * @param str String to be decrypt
     * @return decrypted String
     */
    @Override
    public String decrypt( String str )
    {
        String lReturn = new String();
        try
        {
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] decodedBytes = decoder.decodeBuffer( str );
            lReturn = new String( decodedBytes );
        }
        catch ( IOException ex )
        {
            Logger.getLogger( Base64.class.getName() ).log( Level.SEVERE, null,
                                                            ex );
        }
        return lReturn;
    }

    /**
     * Encrypts the String
     * @param str String to be Encrypt
     * @return Encrypted String
     */
    @Override
    public String encrypt( String str )
    {
        String lReturn = new String();
        BASE64Encoder encoder = new BASE64Encoder();
        lReturn = encoder.encodeBuffer( str.getBytes() );
        return lReturn;
    }
}
